<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>1.Mysql Linux版下载 | 张先生的文档</title>
    <meta name="generator" content="VuePress 1.9.9">
    <link rel="icon" href="zhang.jpeg">
    <meta name="description" content="张先生的文档网页">
    
    <link rel="preload" href="/vue-press/assets/css/0.styles.a2a0458e.css" as="style"><link rel="preload" href="/vue-press/assets/js/app.5f50dbcf.js" as="script"><link rel="preload" href="/vue-press/assets/js/2.733019b2.js" as="script"><link rel="preload" href="/vue-press/assets/js/7.3bd2328a.js" as="script"><link rel="prefetch" href="/vue-press/assets/js/3.bea23741.js"><link rel="prefetch" href="/vue-press/assets/js/4.d12742be.js"><link rel="prefetch" href="/vue-press/assets/js/5.216cae74.js"><link rel="prefetch" href="/vue-press/assets/js/6.2d0a63f8.js"><link rel="prefetch" href="/vue-press/assets/js/8.75c8c290.js">
    <link rel="stylesheet" href="/vue-press/assets/css/0.styles.a2a0458e.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/vue-press/" aria-current="page" class="home-link router-link-exact-active router-link-active"><img src="/vue-press/zhang.jpeg" alt="张先生的文档" class="logo"> <span class="site-name can-hide">张先生的文档</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/vue-press/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  Home
</a></div><div class="nav-item"><a href="https://www.baidu.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
  百度
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://blog.csdn.net" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="/vue-press/blog/fontend/" class="nav-link">
  前端
</a></div><div class="nav-item"><a href="/vue-press/blog/backend/" class="nav-link">
  后端
</a></div><div class="nav-item"><a href="/vue-press/guide/guide.html" class="nav-link">
  导航
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Language Menu" class="dropdown-title"><span class="title">语言</span> <span class="arrow down"></span></button> <button type="button" aria-label="Language Menu" class="mobile-dropdown-title"><span class="title">语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue-press/language/chinese/" class="nav-link">
  中文
</a></li><li class="dropdown-item"><!----> <a href="/vue-press/language/english/" class="nav-link">
  英文
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/vue-press/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  Home
</a></div><div class="nav-item"><a href="https://www.baidu.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
  百度
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://blog.csdn.net" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="/vue-press/blog/fontend/" class="nav-link">
  前端
</a></div><div class="nav-item"><a href="/vue-press/blog/backend/" class="nav-link">
  后端
</a></div><div class="nav-item"><a href="/vue-press/guide/guide.html" class="nav-link">
  导航
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Language Menu" class="dropdown-title"><span class="title">语言</span> <span class="arrow down"></span></button> <button type="button" aria-label="Language Menu" class="mobile-dropdown-title"><span class="title">语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue-press/language/chinese/" class="nav-link">
  中文
</a></li><li class="dropdown-item"><!----> <a href="/vue-press/language/english/" class="nav-link">
  英文
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>1.Mysql Linux版下载</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-press/#_1-mysql-linux版下载" class="sidebar-link">1.Mysql Linux版下载</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_2-执行解压命令" class="sidebar-link">2.执行解压命令</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_3-更改mysql目录下所有的目录及文件夹所属的用户组和用户以及权限" class="sidebar-link">3. 更改mysql目录下所有的目录及文件夹所属的用户组和用户以及权限</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_4-编译安装并初始化mysql" class="sidebar-link">4.编译安装并初始化mysql</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_5-编辑配置文件my-cnf" class="sidebar-link">5.编辑配置文件my.cnf</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_6-启动mysql服务器" class="sidebar-link">6.启动mysql服务器</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_7-添加软连接-并重启mysql服务" class="sidebar-link">7.添加软连接，并重启mysql服务</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_8-登录mysql-修改密码-。" class="sidebar-link">8.登录mysql ， 修改密码 。</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_9-开放所有远程连接" class="sidebar-link">9.开放所有远程连接</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_10-设置开机自动启动" class="sidebar-link">10.设置开机自动启动</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_11-mysql状态、停止、启动" class="sidebar-link">11.mysql状态、停止、启动</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/#_12-如果忘记了mysql密码" class="sidebar-link">12.如果忘记了Mysql密码</a><ul class="sidebar-sub-headers"></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h2 id="_1-mysql-linux版下载"><a href="#_1-mysql-linux版下载" class="header-anchor">#</a> 1.Mysql Linux版下载</h2> <p>下载地址：https://dev.mysql.com/downloads/mysql/</p> <p>选择版本</p> <p><img src="img/mysqlDownload.png" alt=""></p> <p>开始下载</p> <p><img src="img/mysql%E5%BC%80%E5%A7%8B%E4%B8%8B%E8%BD%BD.png" alt=""></p> <h2 id="_2-执行解压命令"><a href="#_2-执行解压命令" class="header-anchor">#</a> 2.执行解压命令</h2> <p>在 <strong>/usr/local/</strong> 目录下创建 <strong>mysql</strong> 文件夹并上传到此文件夹</p> <div class="language- extra-class"><pre class="language-text"><code>mkdir /usr/local/mysql
</code></pre></div><p>解压命令</p> <p>mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz 为压缩包名</p> <div class="language- extra-class"><pre class="language-text"><code>tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz 
</code></pre></div><p>在**/usr/local/mysql**目录下创建data目录</p> <div class="language- extra-class"><pre class="language-text"><code>mkdir /usr/local/mysql/data
</code></pre></div><h2 id="_3-更改mysql目录下所有的目录及文件夹所属的用户组和用户以及权限"><a href="#_3-更改mysql目录下所有的目录及文件夹所属的用户组和用户以及权限" class="header-anchor">#</a> 3. 更改mysql目录下所有的目录及文件夹所属的用户组和用户以及权限</h2> <div class="language- extra-class"><pre class="language-text"><code>chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
</code></pre></div><p>如果报以上错误，说明mysql用户不存在，执行以下命令，操作完再执行更改权限命令</p> <div class="language- extra-class"><pre class="language-text"><code>groupadd mysql
useradd -r -g mysql mysql
</code></pre></div><h2 id="_4-编译安装并初始化mysql"><a href="#_4-编译安装并初始化mysql" class="header-anchor">#</a> 4.编译安装并初始化mysql</h2> <p><strong>务必记住初始化输出日志末尾的密码（数据库管理员临时密码）</strong></p> <div class="language- extra-class"><pre class="language-text"><code>cd /usr/local/mysql/bin 
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
</code></pre></div><p><img src="img/mysqlTempPassword.png" alt=""></p> <h2 id="_5-编辑配置文件my-cnf"><a href="#_5-编辑配置文件my-cnf" class="header-anchor">#</a> 5.编辑配置文件my.cnf</h2> <div class="language- extra-class"><pre class="language-text"><code>[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql/
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
# skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#解决中文乱码问题：
character_set_server=utf8
default-character-set=utf8
</code></pre></div><h2 id="_6-启动mysql服务器"><a href="#_6-启动mysql服务器" class="header-anchor">#</a> 6.启动mysql服务器</h2> <div class="language- extra-class"><pre class="language-text"><code>/usr/local/mysql/support-files/mysql.server start
</code></pre></div><h2 id="_7-添加软连接-并重启mysql服务"><a href="#_7-添加软连接-并重启mysql服务" class="header-anchor">#</a> 7.添加软连接，并重启mysql服务</h2> <p>添加软连接</p> <div class="language- extra-class"><pre class="language-text"><code>ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
</code></pre></div><p>重启mysql服务 ，会有提示ok</p> <div class="language- extra-class"><pre class="language-text"><code>service mysql restart
</code></pre></div><h2 id="_8-登录mysql-修改密码-。"><a href="#_8-登录mysql-修改密码-。" class="header-anchor">#</a> 8.登录mysql ， 修改密码 。</h2> <p>密码为步骤4生成的临时密码</p> <div class="language- extra-class"><pre class="language-text"><code>mysql -u root -p
</code></pre></div><p>使用以下命令修改密码，注意密码不能太简单，否则无法连接，会一直提示修改密码。</p> <div class="language- extra-class"><pre class="language-text"><code>use mysql; //必须先选择数据库
UPDATE user SET authentication_string=PASSWORD('abc123+') WHERE user='root';
</code></pre></div><p>修改MySQL root密码报错：<code>ERROR 1054 (42S22): Unknown column 'password' in 'field list'</code></p> <p>原因：<strong>MySQL 5.7.6 版本将 mysql.user表中的 password 字段移除，提而代之的是 authentication_string 字段。</strong></p> <p>所以，MySQL5.7.6及以上版本更新root密码的sql需要调整为：</p> <div class="language- extra-class"><pre class="language-text"><code>UPDATE user SET authentication_string=PASSWORD('root') WHERE user='root';
</code></pre></div><p>重新加载权限表</p> <div class="language- extra-class"><pre class="language-text"><code>flush privileges;
</code></pre></div><h2 id="_9-开放所有远程连接"><a href="#_9-开放所有远程连接" class="header-anchor">#</a> 9.开放所有远程连接</h2> <p>连接 mysql ，执行命令(注意末尾加分号;)</p> <div class="language- extra-class"><pre class="language-text"><code>mysql&gt;use mysql; //必须先选择数据库
msyql&gt;update user set Host='%' where user='root';
</code></pre></div><h2 id="_10-设置开机自动启动"><a href="#_10-设置开机自动启动" class="header-anchor">#</a> 10.设置开机自动启动</h2> <p>将服务文件拷贝到init.d下，并重命名为mysql</p> <div class="language- extra-class"><pre class="language-text"><code>cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
</code></pre></div><p>赋予可执行权限</p> <div class="language- extra-class"><pre class="language-text"><code>chmod +x /etc/init.d/mysqld
</code></pre></div><p>添加服务</p> <div class="language- extra-class"><pre class="language-text"><code>chkconfig --add mysqld
</code></pre></div><p>显示服务列表</p> <div class="language- extra-class"><pre class="language-text"><code>chkconfig --list
</code></pre></div><h2 id="_11-mysql状态、停止、启动"><a href="#_11-mysql状态、停止、启动" class="header-anchor">#</a> 11.mysql状态、停止、启动</h2> <div class="language- extra-class"><pre class="language-text"><code>service mysql status  // --查看mysql状态   
service mysql stop  //--停止mysql   
service mysql start  //--启动mysql   
</code></pre></div><h2 id="_12-如果忘记了mysql密码"><a href="#_12-如果忘记了mysql密码" class="header-anchor">#</a> 12.如果忘记了Mysql密码</h2> <p>停掉mysql服务</p> <div class="language- extra-class"><pre class="language-text"><code>service mysql stop
</code></pre></div><p>修改/etc/my.cnf 文件，增加 skip-grant-tables ,作用是登陆是跳开密码校验</p> <p><img src="img/mysql%E8%B7%B3%E8%BF%87%E5%AF%86%E7%A0%81%E6%95%88%E9%AA%8C.png" alt=""></p> <p>登陆 mysql -u root, 修改密码</p> <div class="language- extra-class"><pre class="language-text"><code>use mysql;
update user set authentication_string=password('abc123456') where user='root';
</code></pre></div><p>最后重启服务</p> <div class="language- extra-class"><pre class="language-text"><code>service mysql restart
</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <!----> </main></div><div class="global-ui"></div></div>
    <script src="/vue-press/assets/js/app.5f50dbcf.js" defer></script><script src="/vue-press/assets/js/2.733019b2.js" defer></script><script src="/vue-press/assets/js/7.3bd2328a.js" defer></script>
  </body>
</html>
